package edu.pku.sei.mte.mtemodel.mtmodel.common;

import edu.pku.sei.mte.mtemodel.model.MClass;
import edu.pku.sei.mte.utilities.Visitable;
import edu.pku.sei.mte.utilities.Visitor;

public class Key implements Visitable{
	private String[] factors;
	
	public boolean isEqual(MClass l,MClass r){
		if(l==r) return true;
		for(String f : factors){
			Object ol = l.get(f);
			Object or = r.get(f);
			
			if(ol.equals(or)==false)
				return false;
		}
		return true;
	}

	public String[] getFactors() {
		return factors;
	}

	public void setFactors(String[] factors) {
		this.factors = factors;
	}
	
	public boolean containFactor(String f){
		if(f==null) return false;
		for(String s : factors){
			if(s.equals(f))
				return true;
		}
		return false;
	}

	@Override
	public Object accept(Visitor visitor) {
		return visitor.visitKey(this);
	}
}
